<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php

class UserDevice extends CMiniyunModel
{

    
    public function attributeLabels()
    {
        return array(
                'id'               => 'ID',
                'user_id'          => '用户ID',
                'user_device_uuid' => '设备编号',
                'user_device_type' => '设备类型',
                'user_device_name' => '设备名称',
                'user_device_info' => '设备详情',
                'created_at'       => '创建时间',
                'updated_at'       => '修改时间',
        );
    }

    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
    public function tableName()
    {
        return Yii::app()->params['tablePrefix'].'user_devices';
    }

    
    public function  deleteUserDevice($userIds){
        if($userIds!='' && strlen($userIds)>0){
                        $data = $this->findAll("user_id in(".$userIds.")");
            $deviceIds = $this->getIds($data);
                        $serverToken = new ServerToken();
            $serverToken->deleteServerToken($deviceIds);
                        $userDeviceMeta = new UserDeviceMeta();
            $userDeviceMeta->deleteUserDeviceMeta($userIds);
                        $this->deleteAll("user_id in(".$userIds.")");
        }
    }
    
    
    public function findByUserIdAndType($userId,$type) {
        return $this->find("user_id={$userId} and user_device_type=$type");
    }
}